import { getEntireDepartments, getEntireRoles, getEntireMenus } from '@/service/main/main'
import { defineStore } from 'pinia'

interface IMainProp {
  entireRoles: any[]
  entireDepartments: any[]
  entireMenus: any[]
  activeTabs: any[]
}
const userMainStore = defineStore('main', {
  state: (): IMainProp => ({
    entireRoles: [],
    entireDepartments: [],
    entireMenus: [],
    activeTabs: []
  }),
  actions: {
    async fetchEntireDataAction() {
      const rolesResult = await getEntireRoles()
      const departmentsResult = await getEntireDepartments()
      const entireMenusResult = await getEntireMenus()
      this.entireRoles = rolesResult.data.list
      this.entireDepartments = departmentsResult.data.list
      this.entireMenus = entireMenusResult.data.list
    },
    changeTabs(tabs: any) {
      for (const item of this.activeTabs) {
        if (item.id == tabs.id) return
      }
      // if (this.activeTabs.includes(tabs)) return
      this.activeTabs = [...this.activeTabs, tabs]
    },
    deleteTabs(tabs: any) {
      const index = this.activeTabs.indexOf(tabs)
      this.activeTabs.splice(index, 1)
    }
  }
})

export default userMainStore
